// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   register_ok.java

package oa.regulation;

import com.jspsmart.upload.*;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class register_ok extends HttpServlet
{

	public register_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 oa_db = new nseer_db_backup1(dbApplication);
			if (oa_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				mySmartUpload.initialize(pageContext);
				String file_type = getFileLength.getFileType((String)session.getAttribute("unit_db_name"));
				long d = getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
				mySmartUpload.setMaxFileSize(d);
				mySmartUpload.setAllowedFilesList(file_type);
				try
				{
					mySmartUpload.upload();
					String file_name[] = new String[mySmartUpload.getFiles().getCount()];
					int filenum1 = count.read((String)dbSession.getAttribute("unit_db_name"), "oaregulationcount");
					String regulation_ID = (new StringBuilder(String.valueOf(filenum1))).toString();
					count.write((String)dbSession.getAttribute("unit_db_name"), "oaregulationcount", filenum1);
					String sql1 = (new StringBuilder("select * from oa_regulation where regulation_ID='")).append(regulation_ID).append("'").toString();
					ResultSet rs = oa_db.executeQuery(sql1);
					if (rs.next())
					{
						response.sendRedirect("oa/regulation/register_ok_a.jsp");
					} else
					{
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						{
							SmartFile file = mySmartUpload.getFiles().getFile(i);
							if (file.isMissing())
							{
								file_name[i] = "";
							} else
							{
								int filenum = count.read((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount");
								count.write((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount", filenum);
								file_name[i] = (new StringBuilder(String.valueOf(filenum))).append(file.getFileName()).toString();
								file.saveAs((new StringBuilder(String.valueOf(path))).append("oa/file_attachments/").append(filenum).append(file.getFileName()).toString());
							}
						}

						String subject = mySmartUpload.getRequest().getParameter("subject");
						String regulation_type = mySmartUpload.getRequest().getParameter("regulation_type");
						String register = mySmartUpload.getRequest().getParameter("register");
						String register_ID = mySmartUpload.getRequest().getParameter("register_ID");
						String register_time = mySmartUpload.getRequest().getParameter("register_time");
						String content = mySmartUpload.getRequest().getParameter("content");
						String bodyab = new String(mySmartUpload.getRequest().getParameter("remark").getBytes("UTF-8"), "UTF-8");
						String remark = exchange.toHtml(bodyab);
						String fileKind_chain = mySmartUpload.getRequest().getParameter("fileKind_chain");
						String chain_id = Divide1.getId(fileKind_chain);
						String chain_name = Divide1.getName(fileKind_chain);
						String sqla = "insert into oa_regulation(register,register_ID,register_time,regulation_ID,subject,type,content,chain_id,chain_name,remark";
						String sqlb = (new StringBuilder(") values ('")).append(register).append("','").append(register_ID).append("','").append(register_time).append("','").append(regulation_ID).append("','").append(subject).append("','").append(regulation_type).append("','").append(content).append("','").append(chain_id).append("','").append(chain_name).append("','").append(remark).append("'").toString();
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						{
							int p = i + 1;
							sqla = (new StringBuilder(String.valueOf(sqla))).append(",attachment").append(p).toString();
							sqlb = (new StringBuilder(String.valueOf(sqlb))).append(",'").append(file_name[i]).append("'").toString();
						}

						String sql = (new StringBuilder(String.valueOf(sqla))).append(sqlb).append(")").toString();
						oa_db.executeUpdate(sql);
						List rsList = GetWorkflow.getList(oa_db, "oa_config_workflow", "03");
						String elem[] = new String[3];
						if (rsList.size() == 0)
						{
							String sql2 = (new StringBuilder("update oa_regulation set check_tag='1' where regulation_ID='")).append(regulation_ID).append("'").toString();
							oa_db.executeUpdate(sql2);
						} else
						{
							for (Iterator ite = rsList.iterator(); ite.hasNext(); oa_db.executeUpdate(sql))
							{
								elem = (String[])ite.next();
								sql = (new StringBuilder("insert into oa_workflow(config_id,object_ID,describe1,describe2,type_id) values ('")).append(elem[0]).append("','").append(regulation_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("','03')").toString();
							}

						}
						response.sendRedirect("oa/regulation/register_ok_b.jsp");
					}
				}
				catch (Exception ex)
				{
					response.sendRedirect("oa/regulation/register_ok_c.jsp");
				}
				oa_db.commit();
				oa_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
